<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path=request.getContextPath();
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<base href="<%=basePath%>">
	<title><s:text name="sys.app_title" /></title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<%@include file="../include/contentheader.jsp"%>
	<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="js/app.js"></script>
	<link rel="stylesheet" type="text/css" href="css/main.css"/>
	<link rel="StyleSheet" type="text/css" href="css/dtree.css"/>
	<script type="text/javascript" src="js/dtree.js"></script>
	
	<script type="text/javascript" src="dwr/engine.js"></script>
	<script type="text/javascript" src="dwr/util.js"></script>
	<script type="text/javascript" src="dwr/interface/departmentDwrJs.js"></script>
	<script type="text/javascript" src="js/dep.js"></script>
	<link rel="StyleSheet" href="css/dep.css" type="text/css" />
</head>

<body onload="buildTree()">
	<div class="mainContainer">
   	<div class="headerTitle">基础信息管理&nbsp;>>&nbsp;部门管理</div>
       	<div class="dtreeDiv" id="myTree">
       		<script type="text/javascript">
       		var myTree=document.getElementById("myTree");
   			d = new dTree('d');
   			var inner;
   			function buildTree(){
   				departmentDwrJs.getAllDepartment(function(departmentList) {
   				d.add(0, -1, '广元电业局','searchDepartment.action');
    			for(var i=0; i<departmentList.length; i++){
        			for(var j=0; j<departmentList.length; j++){
            			if(departmentList[i].depid==departmentList[j].depparentid){
        					d.add(departmentList[j].depid,departmentList[j].depparentid,departmentList[j].depname,'selectDepartmentInTree.action?depid='+departmentList[j].depid);
        				}
            		}
    			}
    			inner = d.toString();
    			showBuildTree();
    			});
    		}
			function showBuildTree(){
				myTree.innerHTML = inner;
	  	 	}
			</script>
        </div>
        <div class="dataDivLeftHasTree">
        	<table class="gridTable" border="0" cellspacing="0" cellpadding="0">
				<tr class="operatorAction">
					<td>
					<!-- 功能性操作 -->
					<input type="button" style="margin-left:2px;" value="刷新" onclick="doRefresh()"/>
					<input type="button" style="margin-left:2px;" value="新增" onclick="doAdd();"/>
					<input type="button" style="margin-left:2px;" value="修改" onclick="doEdit()"/>
					<input type="button" style="margin-left:2px;" value="删除" onclick="doDel();"/>
					<input type="button" style="margin-left:2px;" value="导出" onclick="doExport()"/>
					
					查询条件：根据&nbsp;&nbsp;<select style="width: 94px;"  id="condition">
	  					<option value="depname" selected="selected">部门名称</option>
						<option value="depsimplename">部门简称</option>
						<option value="depid">部门编号</option>
	  				</select><input style="margin-left:10px;" type="text" id="conditionValue"/>
	  				<input type="button" style="margin-left:1px;" value="查询" onclick="selectDep()"/>
	  				
					</td>
				</tr>
				<tr>
					<td class="gridData">
	        			<table class="dataTable" border="0" cellpadding="0" cellspacing="1">
	          				<tr class="dataHeader">
	          				<!-- 数据表头 -->
					            <td width="5%"><input id="checkAll" type="checkbox" /></td>
					            <td width="19%">部门名称</td>
					            <td width="19%">部门简称</td>
					            <td width="19%">负责人</td>
					            <td width="19%">经办人</td>
					            <td width="19%">部门状态</td>
							</tr>
							<!-- 数据 -->
	         				<s:iterator value="pagination.dataList"> 
	          				<tr class="dataRow" id="<s:property value='depid'/>" ondblclick="doDctr('<s:property value="depid" />')">
					            <td><input name="checkbox" type="checkbox" value="<s:property value='depid'/>" /></td>
					            <td><s:property value="depname"/></td>
					            <td><s:property value="depsimplename"/></td>
					            <td>
					            	<s:iterator value="staffs">
					            		<s:if test='fzr=="Y"'><s:property value='staname'/></s:if>
					            	</s:iterator>
					            </td>
					            <td>
					            	<s:iterator value="staffs">
					            		<s:if test='jbr=="Y"'><s:property value='staname'/></s:if>
					            	</s:iterator>
					            </td>
					            <td>
					            	<s:if test='depstatus=="A"'><div style="color: #0f0;">在用</div></s:if>
					            	<s:elseif test='depstatus=="D"'><div style="color: #f00;">弃用</div></s:elseif>
					            </td>
	          				</tr>
	      					</s:iterator>
						</table>
					</td>
				</tr>
				<tr class="dataPager">
					<td>
						<s:property value="pageLink" escapeHtml="false" />
					</td>
				</tr>
			</table>
        </div>
	</div>
	<form action="" method="post" id="HIDDENFORM" name="HIDDENFORM">
		<input type="hidden" id="FN" name="FN" value="<s:property value='FN' />" />
		<input type="hidden" id="dId" name="dId" value="" />
	</form>
	
	<script type="text/javascript">
		function doRefresh(){
			location.href="searchDepartment.action";
		}
		function doAdd(){
			location.href='page/basic/addNewDep.jsp';
		}
		function doEdit(){
			var allDepid = $("input:checked");
		    if(allDepid.length == 0){
	    		alert("你还没有选择要修改的部门");
		    }else if(allDepid.length == 1){
		    	location.href = "selectDepartmentById.action?depid="+allDepid[0].value;
		    }else{
		    	alert("每次只能修改一个部门");
			}
		}
		function doDel(){
			var checkboxs=document.getElementsByName("checkbox");
			var str="";
			var checked=0;
			for(var i=0;i<checkboxs.length;i++){		
				if(checkboxs[i].checked){
					str=str+checkboxs[i].value+",";
					checked++;
				}
			}
			if(checked==0){
				alert("没有选择部门无法完成删除功能");
			}else{
				var a=confirm("确定要删除所选记录吗?删除之后将不能恢复!");
				if(a){
					window.location.href="deleteChoosedDepartment.action?depidAll="+str;
				}
			}
		}
		function doExport(){
			if(confirm("确定要导出所有记录吗?")){
				window.location.href="execute.action";
			}
		}
		function doDctr(depid){
			location.href = "selectDepartmentById.action?depid="+depid;
		}
		function selectDep(){
			var inputValue=document.getElementById("conditionValue").value;
			var chus=document.getElementById("condition");
			var chusValue=chus.options[chus.selectedIndex].value;
			var pageNumber=1;
			if(inputValue==""){
				alert("条件为空值，将会查询出所有的记录");
				window.location.href="searchDepartment.action?page="+pageNumber;
			}else{
				window.location.href="searchDepartmentByPageNumberAndValue.action?page="+pageNumber+"&property="+chusValue+"&value="+inputValue;
			}
		}
	</script>
</body>
</html>
